package com.album.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class BaseDao {
	private String driverUrl="com.mysql.cj.jdbc.Driver";
	private String url="jdbc:mysql://localhost:3306/album?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8&useSSL=false";
	private String userName = "root";
	private String password = "123456";
	
	public Connection getConnection() {
		Connection con = null;
		try {
			Class.forName(driverUrl);
			con = DriverManager.getConnection(url, userName, password);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return con;
		
	}
	
	public void close(Connection con, Statement st) {
		try {
			if (st!=null) {
				st.close();
			}
			if(con!=null) {
				con.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
/*	public static void main(String[] args) {
		BaseDao bd = new BaseDao();
		Connection con=bd.getConnection();
		System.out.println(con);
		try {
			con.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}*/
}
